package ar.posti.framework.query.core.filter;

import java.util.Map;

/**
 * @author Posti
 */
public class BooleanExpression implements BooleanCriteria {
	private BooleanCriteria filter;

	public BooleanExpression(BooleanCriteria filter) {
		this.setFilter(filter);
	}

	/* (non-Javadoc)
	 * @see ml.pms.query.filter.BooleanFilter#and(ml.pms.query.filter.BooleanFilter)
	 */
	public BooleanCriteria and(BooleanCriteria filter) {
		return this.filter.and(filter);
	}

	/* (non-Javadoc)
	 * @see ml.pms.query.filter.BooleanFilter#or(ml.pms.query.filter.BooleanFilter)
	 */
	public BooleanCriteria or(BooleanCriteria filter) {
		return this.filter.or(filter);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		if (this.filter.isActive()) {
			buffer.append("(");
			buffer.append(this.filter.toString());
			buffer.append(")");
		}

		return buffer.toString();
	}
	
	private void setFilter(BooleanCriteria filter) {
		this.filter = filter;
	}

	public boolean isActive() {
		return filter.isActive();
	}

	public Map<String, Object> getVariables() {
		return filter.getVariables();
	}

    public void bindVariable(String parameter, Object value) {
        filter.bindVariable(parameter, value);
    }
}
